package com.zipkin.handler;

import com.netflix.zuul.ZuulFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.stereotype.Component;

/**
 * @ClassName: ZuulCustomFilter
 * @Author: ZhangYue26
 * @Description: 假设一个这样的需求，在请求上添加操作人员信息,通过Tracer添加操作人员信息
 * @Date: 2021-01-18
 */
@Component
public class ZuulCustomFilter extends ZuulFilter {

    @Autowired
    Tracer tracer;

    @Override
    public String filterType() {
        return FilterConstants.POST_TYPE;
    }

    @Override
    public int filterOrder() {
        return 900;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        tracer.addTag("operator","admin");
        System.out.println(tracer.getCurrentSpan().traceIdString());
        return null;
    }
}
